<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        #box{
            width: 800px;
            height: 200px;
            border: 3px solid #999;
            margin: 20px auto;
            overflow: scroll;
        }
        #content{
            width: 10000px;
        }
        #imglist{
            float: left;
        }
        #imglist img{
            width: 300px;
            height: 200px;
            float: left;
        }
    </style>
    <script src="./jquery-3.3.1.min.js"></script>
</head>
<body>
    <h1>图片无缝滚动</h1>

    <hr>

    <div id="box">
        <div id="content">
            <div id="imglist">
                <img src="./imgs/mm001.jpg">
                <img src="./imgs/mm002.jpg">
                <img src="./imgs/mm003.jpg">
                <img src="./imgs/mm004.jpg">
                <img src="./imgs/mm005.jpg">
                <img src="./imgs/mm006.jpg">
                <img src="./imgs/mm007.jpg">
                <img src="./imgs/mm008.jpg">
                <img src="./imgs/mm009.jpg">
                <img src="./imgs/mm010.jpg">
                <img src="./imgs/mm011.jpg">
                <img src="./imgs/mm012.jpg">
                <img src="./imgs/mm013.jpg">
                <img src="./imgs/mm014.jpg">
                <img src="./imgs/mm015.jpg">
            </div>
        </div>
    </div>


    <script>
        $(function(){
            // 获取一轮图片的宽度
            var width = $('#imglist').innerWidth();
            // console.log(width);
            // 将图片克隆一份,并追加到当前图片之后
            $('#imglist').clone().appendTo('#content');

            function scrollImage(){
                // 判断回滚临界点
                if ($('#box').scrollLeft() >= width) {
                    $('#box').scrollLeft(0);
                }
                $('#box').scrollLeft($('#box').scrollLeft() + 1);
            }
            // 定时器 一直滚
            setInterval(scrollImage, 1);
        });
        
    </script>



</body>
</html>




